package com.goods.shop.service.yidu;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.goods.shop.model.yidu.*;

import com.goods.shop.util.HttpUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class YiDuServerImpl {
    private static Logger logger= LoggerFactory.getLogger(YiDuServerImpl.class);
    private final String  SAVEACCESSURL="http://moedu.cmbc.com.cn/edu/resmgt/resource!saveAccessPeriod.action";
    private final String  GETMODULETREEURL="http://moedu.cmbc.com.cn/edu/learn/course!getModuleTree.action";
    private final String  PLAYERDATAURL="http://moedu.cmbc.com.cn/edu/resmgt/resource!playerData.action";
    private final String  PLAYERACTIONURL="http://moedu.cmbc.com.cn/edu/resmgt/resource!player.action";
    //获取课程列表
    private final String  COURSELISTURL="http://nedu.cmbc.com.cn/newcmbcedu/portal/homenotice/labelDetail";
    private final String  OPENCOURSEURL="http://nedu.cmbc.com.cn/newcmbcedu/newportal/rnhome/openCourse";
    private final String  SSOURL="http://moedu.cmbc.com.cn/edu/j_sso";
    private final String  TOCOURSEDETAILURL="http://moedu.cmbc.com.cn/edu/course/toCourseDetail.action";


    public static final String ACTATTID="actAttId";
    public static final String ID="id";
    public static final String MODID="modId";
    public static final String SYSTIME="systime";

    private Pattern pattern= Pattern.compile("([a-z0-9]{80})");
    public Map<String, String> generateHeader(String cookie)
    {
        Map<String, String> headers = new HashMap<>();
        headers.put("Accept", "application/json, text/plain, */*");
        headers.put("Accept-Encoding", "gzip, deflate");
        headers.put("Accept-Language", "zh-CN,en-US;q=0.9");
        headers.put("Connection", "keep-alive");
        headers.put("Host", "moedu.cmbc.com.cn");
//        headers.put("Origin", "http://moedu.cmbc.com.cn/");
        headers.put("Referer","http://moedu.cmbc.com.cn/edu/course/toCourseDetail.action?data=f9d54db2656c494c93a6277bc6c89285a0ab0f2c747187955b7a7db1908808363f5778db6b2b1059");
        headers.put("User-Agent",
                "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3423.2 Safari/537.36");
        headers.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36");
        headers.put("Cookie",cookie);
        return headers;
    }
    @Deprecated
    public Map<String, String> generateCourseListHeader(String cookie,String curJsSessionId)
    {
        Map<String, String> headers = new HashMap<>();
        headers.put("Accept", "*/*");
        headers.put("Accept-Encoding", "gzip, deflate");
        headers.put("Accept-Language", "zh-CN,en-US;q=0.9");
        headers.put("Connection", "keep-alive");
        headers.put("Host", "nedu.cmbc.com.cn");
        headers.put("Origin", "http://nedu.cmbc.com.cn");
        headers.put("Referer","http://nedu.cmbc.com.cn/newcmbcedu/gotoIndexNew?curJsSessionId="+curJsSessionId);
        headers.put("User-Agent",
                "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3423.2 Safari/537.36");
        headers.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36");
        headers.put("X-Requested-With","XMLHttpRequest");
        headers.put("Cookie",cookie);
        return headers;
    }
    public Map<String, String> generateCourseDetailHeader(String cookie,String courseid)
    {
        Map<String, String> headers = new HashMap<>();
        headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
        headers.put("Accept-Encoding", "gzip, deflate");
        headers.put("Accept-Language", "zh-CN,en-US;q=0.9");
        headers.put("Cache-Control", "max-age=0");
        headers.put("Connection", "keep-alive");
        headers.put("Host", "moedu.cmbc.com.cn");
//        headers.put("Origin", "http://nedu.cmbc.com.cn");
        headers.put("Referer","http://nedu.cmbc.com.cn/newcmbcedu/newportal/rnhome/openCourse?itmid="+courseid);
        headers.put("Upgrade-Insecure-Requests","1");
        headers.put("User-Agent",
                "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3423.2 Safari/537.36");
        headers.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36");
        headers.put("Cookie",cookie);
        return headers;
    }
    public List<ActivityModel> courseList(String cookie, String lableId,String curJsSessionId) {
        List<ActivityModel> courses=new ArrayList<>();
        Map<String, String> headers =generateHeader(cookie);
        Map<String, Object> bodyParams =new HashMap<>();
        bodyParams.put("labelid",lableId);
        bodyParams.put("_",System.currentTimeMillis());
        bodyParams.put("curJsSessionId",curJsSessionId);
        String result= HttpUtils.requestPost(COURSELISTURL,headers,bodyParams);
//        System.out.println("courseList.result="+result);
        Document htmlDocument=Jsoup.parse(result);
        Elements trElements=htmlDocument.select("tbody").select("tr");
        for(Element trElement:trElements){
            Element aElement=trElement.selectFirst("a[class='u-signup']");
            String onclick=aElement.attr("onclick");
            String courseId=onclick.substring(16,21);
            System.out.println(onclick+"-"+courseId);
        }
        return courses;
    }
    //获取长的DATA串
    public String openCourse(String cookie, String courseId) {
        Map<String, String> headers =generateHeader(cookie);
        Map<String, Object> bodyParams =new HashMap<>();
        bodyParams.put("itmid","xb"+courseId);
        String result=HttpUtils.requestGet(OPENCOURSEURL,headers,bodyParams);
        System.out.println("openCourse.result="+result);
        Matcher matcher=pattern.matcher(result);
        String data="";
        if(((Matcher) matcher).find()){
            data=matcher.group(1);
        }
        return data;
    }
    public String toCourseDetail(String cookie, String courseId,String data) {
        Map<String, String> headers =generateCourseDetailHeader(cookie,"xb"+courseId);
        Map<String, Object> bodyParams =new HashMap<>();

        bodyParams.put("data",data);
        String result=HttpUtils.requestGet(TOCOURSEDETAILURL,headers,bodyParams);
        logger.info("toCourseDetail.result="+result);
        return result;
    }
    public String sso(String cookie, String courseId) {
        Map<String, String> headers =generateCourseDetailHeader(cookie,"xb"+courseId);
        Map<String, Object> bodyParams =new HashMap<>();

        bodyParams.put("type","course");
        bodyParams.put("token","009a4254c517a585d264bd1e689c5e45");
        String result=HttpUtils.requestGet(SSOURL,headers,bodyParams);
        System.out.println("sso.result="+result);
        return result;
    }
    public List<ModelTree> getModuleTree(String cookie,ActivityModel activityModel) {
        List<ModelTree> results=new ArrayList<>();
        Map<String, String> headers =generateHeader(cookie);
        Map<String, Object> bodyParams =new HashMap<>();
//        bodyParams.put("activity.id","28561");
//        bodyParams.put("activityAttendance.id","15781134");
        bodyParams.put("activity.id",activityModel.getActivityId());//对应的课程的ID
        bodyParams.put("activityAttendance.id",activityModel.getActivityAttendanceId());
        bodyParams.put("delayLoad",false);
        String result=HttpUtils.requestGet(GETMODULETREEURL,headers,bodyParams);
        logger.info("getModuleTree.result="+result);
        JSONArray resultArrays=JSONObject.parseArray(result);
        for(int i=0,length=resultArrays.size();i<length;i++){
            JSONObject o=resultArrays.getJSONObject(i);
            ModelTree tree=o.toJavaObject(ModelTree.class);
            results.add(tree);
        }
        return results;
    }
    public String playerData(String cookie, YiDuModel vo) {
        Map<String, String> headers =generateHeader(cookie);
        Map<String, Object> bodyParams =new HashMap<>();
        bodyParams.put("actAttId",vo.getActAttId());
        bodyParams.put("id",vo.getId());
        bodyParams.put("modId",vo.getModId());
        String result=HttpUtils.requestGet(PLAYERDATAURL,headers,bodyParams);
        logger.info("playerData.bodyParams==={},result={}",JSONObject.toJSONString(bodyParams),result);
        return result;
    }
    public String playerAction(String cookie, YiDuModel vo) {
        Map<String, String> headers =generateHeader(cookie);
        Map<String, Object> bodyParams =new HashMap<>();
        bodyParams.put("actAttId",vo.getActAttId());
        bodyParams.put("id",vo.getId());
        bodyParams.put("modId",vo.getModId());
        bodyParams.put("resType",vo.getTypecode().toString());
        bodyParams.put("decorate",false);

        String result=HttpUtils.requestGet(PLAYERACTIONURL,headers,bodyParams);
//        logger.info("playerAction.bodyParams==={},result={}",JSONObject.toJSONString(bodyParams),result);
        return result;
    }
    public int saveAccess(String cookie, YiDuModel vo) {
        Map<String, String> headers =generateHeader(cookie);
        Map<String, Object> bodyParams =new HashMap<>();
        bodyParams.put("actAttId",vo.getActAttId());
        bodyParams.put("id",vo.getId());
        bodyParams.put("modId",vo.getModId());
        String result=HttpUtils.requestGet(SAVEACCESSURL,headers,bodyParams);
        JSONObject jsonObject= JSONObject.parseObject(result);
        int code=jsonObject.getIntValue("code");
        logger.info("saveAccess.bodyParams==={},result={}",JSONObject.toJSONString(bodyParams),result);
        if(code==0){
            JSONObject resAttendance=jsonObject.getJSONObject("resAttendance");
            return resAttendance.getIntValue("modattemptperiod2");
        }
        return 0;
    }
    public void execute(String cookie, ModelTree tree,ActivityModel activityModel,CountDownLatch latcher) {
        YiDuModel vo=generateYiDuModel(tree,activityModel);
        LocalDateTime time=LocalDateTime.now();
        logger.info("单门课程:"+activityModel.getActivityId()+"，单个章节，开始执行:"+tree.toString());
        //TODO----actAttId~15949536~id~23546~modId~23794=1600322553619
        String valueCookie=cookie.replaceAll("\\{"+ACTATTID+"\\}",vo.getActAttId()).replaceAll("\\{"+ID+"\\}",vo.getId())
                .replaceAll("\\{"+MODID+"\\}",vo.getModId());
        long startMillis=time.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        String playCookie=valueCookie.replaceAll("\\{"+SYSTIME+"\\}",String.valueOf(startMillis));


        logger.info("cookie==="+playCookie);
        playerData(playCookie,vo);
        playerAction(playCookie,vo);
        long needSeconds=tree.getCompletedperiod()*60;
        long viewedSeconds=tree.getModattemptperiod2();
////        //TODO----
//        if(needSeconds>viewedSeconds){
//            try {
//        long shouldViewSeconds=needSeconds-viewedSeconds+10;
        long shouldViewSeconds=needSeconds+10;
//                logger.info("单门课程:"+activityModel.getActivityId()+"，单个章节："+tree.getId()+",需要浏览"+shouldViewSeconds+"秒");
//                TimeUnit.SECONDS.sleep(shouldViewSeconds);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
        int countTimes=0;
        long sourceStartMills=startMillis-shouldViewSeconds*1000;
        String saveCookie=valueCookie.replaceAll("\\{"+SYSTIME+"\\}",String.valueOf(sourceStartMills));
        int restSeconds= saveAccess(saveCookie,vo);
//        while(restSeconds<shouldViewSeconds){
//            try {
//                TimeUnit.SECONDS.sleep(1);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
////            restSeconds= saveAccess(saveCookie,vo);
////            logger.info("saveCookie={}",saveCookie);
//            restSeconds=saveAccess(saveCookie,vo);
////            countTimes++;
//        }



//
        latcher.countDown();
//        logger.info("单门课程:"+activityModel.getActivityId()+"，单个章节，开始完成:"+tree.toString()+",花费时间:"+tree.getCompletedperiod()+"分钟！");
    }
    public void executeStudyCourse(String cookie,ActivityModel activityModel,CountDownLatch totalLatcher){
        List<ModelTree> trees=getModuleTree(cookie,activityModel);
        ExecutorService executors= Executors.newCachedThreadPool();
        int count=0;
        for(ModelTree tree:trees){
            if(!tree.getModstatus().equals("已完成")){
                count++;
            }
//            logger.info("tree={}",tree.toString());
        }
        CountDownLatch latcher=new CountDownLatch(count);
        long startTime=System.currentTimeMillis();
        for(ModelTree tree:trees){
            logger.info(tree.toString());
            if(!tree.getModstatus().equals("已完成")){
                Thread t=new Thread(()->{
                    execute(cookie,tree,activityModel,latcher);
                });
                executors.execute(t);
            }
        }
        try {
            latcher.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long endTime=System.currentTimeMillis();
        logger.info("单门课程："+activityModel.toString()+",全部执行完成,总花费时间:"+(endTime-startTime)/1000+"秒");

        totalLatcher.countDown();
        logger.info("totalLatcher.countDown"+activityModel.toString()+",totalLatcher.size="+totalLatcher.getCount());
    }
    public YiDuModel generateYiDuModel(ModelTree tree,ActivityModel activityModel) {
        YiDuModel vo=new YiDuModel();

//        vo.setActAttId("15781134");//TODO 了解一下各个含义
//        vo.setId("25925");//TODO 了解一下各个含义
//        vo.setModId("26173");//TODO 了解一下各个含义
        vo.setActAttId(activityModel.getActivityAttendanceId());
        vo.setTypecode(CourseType.valueOf(tree.getTypecode()));
        vo.setId(tree.getId());
        vo.setModId(tree.getModuleid());
        return vo;
    }
    public void test(String cookie,ModelTree tree,ActivityModel activityModel){
        YiDuModel vo=generateYiDuModel(tree,activityModel);
        playerData(cookie,vo);
        playerAction(cookie,vo);
        saveAccess(cookie,vo);
    }
    public static void main(String[] args) {
        //TODO
//        String cookie="actAttId~15935618~id~26823~modId~27071=1600168450275; actAttId~15929126~id~26714~modId~26962=1600168614252; SOAMCOOKIE=ROJvgTUI3fVmD3M4edtzT0/1ZnEv2T3NVjfgF8SqG9zGMV0qElriJHAmnCY7XUzXj2Tg76rhQUxqJ5K/69NBprQQthHELIRu5uw6VhCQHiW5u2JAWka0HU7hiC8tB8GcjX1g4zZZ8pYS88/03tAp3Ouq5yZ/c1yLE3QTOHm30Sw=; loginName=lishengwang; OACOOKIE=\"ROJvgTUI3fVmD3M4edtzT0/1ZnEv2T3NVjfgF8SqG9zGMV0qElriJHAmnCY7XUzXj2Tg76rhQUxqJ5K/69NBprQQthHELIRu5uw6VhCQHiW5u2JAWka0HU7hiC8tB8GcjX1g4zZZ8pYS88/03tAp3Ouq5yZ/c1yLE3QTOHm30Sw=\"; CmbcSession=3EA8548D148051F66D9214484D221E4B; CmbcSessionTime=3EA8548D148051F66D9214484D221E4B; BIGipServeryidongxuexixitong-APP_7080_pool=!cbuaZ+HtkhFUWcZE+HLHHQXNQUFscqseSGFy5fhcWzRkLc2NM4KaCElN61n4MISRH+FbxBE124jp; JSESSIONID=iQORX-wiZhxgrNgFfRF_v3MiT2y7X_TwJ98e35N6xXy8a_D3j21T!-1561121939; BIGipServeryidongxuexixitong-wenjianfuwu_80_pool=!fehfOZdQ3kwDat5E+HLHHQXNQUFscuB2QewAMK64hshEu6L9lbSipBNNv019s5OgkaniDAwYU3Pe";
        String cookie="HMM36=00000000000000000000000000000000000000000000000000|*10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000|; SOAMCOOKIE=Lgm31OsRuLNFbHZ6dXpA3Zrm2YuWvStnnGPW8L0x1GdK9JDT+JMedUgmXgPRy4SS25zQcIIFLAgmfbmNWFmH1oz/Vjm25wnXERvT/dm8WS5UDyB/nUz8tvyf+L6BtewZQ7uARyM3HBMI/qvFDmgAeZZL0i/YyXJaSqGSEyLe+XY=; loginName=huyifang; CmbcSession=D6AF02BF3E05BD56CDD6B0772FAFB473; OACOOKIE=\"Lgm31OsRuLNFbHZ6dXpA3Zrm2YuWvStnnGPW8L0x1GdK9JDT+JMedUgmXgPRy4SS25zQcIIFLAgmfbmNWFmH1oz/Vjm25wnXERvT/dm8WS5UDyB/nUz8tvyf+L6BtewZQ7uARyM3HBMI/qvFDmgAeZZL0i/YyXJaSqGSEyLe+XY=\"; CmbcSessionTime=D6AF02BF3E05BD56CDD6B0772FAFB473; BIGipServeryidongxuexixitong-APP_7080_pool=!2mEpbDvBFiDjFqVE+HLHHQXNQUFscvKiKy3ncygnPHj6fuTwazdCKnJv9q8AwGzV0MtB8C3hp0El; JSESSIONID=8gljqWhvgBjVBQV3ODLKeIv19d9u18AGt3rMFJy9nIjlA20TpHG-!1443476817";
        String courseCookie="actAttId~{"+ACTATTID+"}~id~{"+ID+"}~modId~{"+MODID+"}={"+SYSTIME+"};"+cookie;
        YiDuServerImpl service=new YiDuServerImpl();
        List<ActivityModel> activitys=new ArrayList<>();

//        //2020年度法治民生
//        activitys.add(new ActivityModel("29268","15812926"));//第一个值为 课程的ID,第二个值为 TODO 民法典人格权编与金融消费者的个人信息保护
//        activitys.add(new ActivityModel("29270","15812930"));//第一个值为 课程的ID,第二个值为 TODO 民法典侵权责任编解读
//        activitys.add(new ActivityModel("29269","15812934"));//第一个值为 课程的ID,第二个值为 TODO 民法典婚姻继承编解读
//        activitys.add(new ActivityModel("29266","15812937"));//第一个值为 课程的ID,第二个值为 TODO 民法典融资租赁合同章与融资租赁实务
//        activitys.add(new ActivityModel("29264","15929126"));//第一个值为 课程的ID,第二个值为 TODO 民法典保证合同章与金融担保实务
//        activitys.add(new ActivityModel("29409","15812948"));//第一个值为 课程的ID,第二个值为 TODO 民法典总则编解读
//        activitys.add(new ActivityModel("29410","15812952"));//第一个值为 课程的ID,第二个值为 TODO 民法典的时代精神与中国特色
//        activitys.add(new ActivityModel("29265","15935618"));//第一个值为 课程的ID,第二个值为 TODO 民法典担保物权分编与金融担保实务
//        activitys.add(new ActivityModel("29263","15812967"));//第一个值为 课程的ID,第二个值为 TODO 民法典合同编若干问题及借款合同
//        activitys.add(new ActivityModel("29262","15812974"));//第一个值为 课程的ID,第二个值为 TODO 民法典合同编通则分编的修改对于金融合同的影响
//        activitys.add(new ActivityModel("29267","15812978"));//第一个值为 课程的ID,第二个值为 TODO 民法典保理合同章与保理实务
//        activitys.add(new ActivityModel("27478","15812983"));//第一个值为 课程的ID,第二个值为 TODO 全国法院民商事审判工作会议纪要专题解读——授信担保、金融产品销售、票据
//        activitys.add(new ActivityModel("27479","15812985"));//第一个值为 课程的ID,第二个值为 TODO 全国法院民商事审判工作会议纪要专题解读——资管、投行股权直投、供应链金融
//        activitys.add(new ActivityModel("27480","15812990"));//第一个值为 课程的ID,第二个值为 TODO 全国法院民商事审判工作会议纪要专题解读——不良资产处置
//
//       // 2020年度科技金融
//        activitys.add(new ActivityModel("28552","15812996"));//第一个值为 课程的ID,第二个值为 TODO 5G时代下的机会与挑战
//        activitys.add(new ActivityModel("28561","15812997"));//第一个值为 课程的ID,第二个值为 TODO 互联网金融生态系统2020：新动力、新格局、新战略
//        activitys.add(new ActivityModel("28573","15803433"));//第一个值为 课程的ID,第二个值为 TODO 数据分析思维——系统性思维框架搭建与分析型思维应用
//        activitys.add(new ActivityModel("29280","15813001"));//第一个值为 课程的ID,第二个值为 TODO 中国民生银行创新技术的应用与实践
//
//        //2020年度内控合规
//        activitys.add(new ActivityModel("10844","15813007"));//第一个值为 课程的ID,第二个值为 TODO   反洗钱现场检查的问题分析
//        activitys.add(new ActivityModel("19418","15813014"));//第一个值为 课程的ID,第二个值为 TODO  银行从业人员刑事犯罪罪名解析与案例分析
//        activitys.add(new ActivityModel("19525","15935846"));//第一个值为 课程的ID,第二个值为 TODO  金融科技的政策、风险与防范及争议解决
////        activitys.add(new ActivityModel("20458","15813023"));//第一个值为 课程的ID,第二个值为 TODO  银行实务中的担保法律问题---非视频
////        activitys.add(new ActivityModel("20458","10614049"));//第一个值为 课程的ID,第二个值为 TODO  保函外汇合规政策解析---非视频
//          activitys.add(new ActivityModel("20560","15935900"));//第一个值为 课程的ID,第二个值为 TODO  中国民生银行反洗钱基础知识
//        activitys.add(new ActivityModel("20664","15935878"));//第一个值为 课程的ID,第二个值为 TODO  中国民生银行员工违规违纪行为处分办法
////
//        activitys.add(new ActivityModel("20883","15813047"));//第一个值为 课程的ID,第二个值为 TODO   银行业从业人员职业操守
//        activitys.add(new ActivityModel("21052","15935848"));//第一个值为 课程的ID,第二个值为 TODO  中国民生银行保密基础知识
//        activitys.add(new ActivityModel("21057","15813050"));//第一个值为 课程的ID,第二个值为 TODO  银行业金融机构从业人员行为管理指引
//        activitys.add(new ActivityModel("21062","15935851"));//第一个值为 课程的ID,第二个值为 TODO  商业银行合规类相关基础知识
//
//
//
////        activitys.add(new ActivityModel("21253","15782303"));//第一个值为 课程的ID,第二个值为 TODO  公证与银行业务--非视频
////        activitys.add(new ActivityModel("21577","15786020"));//第一个值为 课程的ID,第二个值为 TODO  协助执行业务常见法律问题与应对措施--非视频
////        activitys.add(new ActivityModel("21578","15813061"));//第一个值为 课程的ID,第二个值为 TODO  柜面业务操作法律风险--非视频
//
//
//        activitys.add(new ActivityModel("21620","15813064"));//第一个值为 课程的ID,第二个值为 TODO  中国民生银行内控合规管理介绍
//        activitys.add(new ActivityModel("22144","15813079"));//第一个值为 课程的ID,第二个值为 TODO  银行业专业人员职业资格风险管理（中级）-银行监管与市场约束
////        activitys.add(new ActivityModel("22862","15813083"));//第一个值为 课程的ID,第二个值为 TODO  银行及其工作人员常见金融及职务犯罪探析--非视频
//        activitys.add(new ActivityModel("23935","15813086"));//第一个值为 课程的ID,第二个值为 TODO  中国民生银行《内部控制办法》及《合规管理办法》解读
////
//        activitys.add(new ActivityModel("24238","16072004"));//第一个值为 课程的ID,第二个值为 TODO  新金融工具会计准则解读
//        activitys.add(new ActivityModel("24246","15950913"));//第一个值为 课程的ID,第二个值为 TODO  财政部财务快报及决算报表填报指引
//        activitys.add(new ActivityModel("24321","15950897"));//第一个值为 课程的ID,第二个值为 TODO  会计报表和科目归属主要变化介绍
//        activitys.add(new ActivityModel("24955","15813196"));//第一个值为 课程的ID,第二个值为 TODO  商业银行关联交易基础知识
//        activitys.add(new ActivityModel("25263","15813199"));//第一个值为 课程的ID,第二个值为 TODO 中国民生银行制度管理规范及应用系统操作
//        activitys.add(new ActivityModel("25730","12553880"));//第一个值为 课程的ID,第二个值为 TODO  保密微课堂-保密常识我知道

//        activitys.add(new ActivityModel("26198","15949536"));//第一个值为 课程的ID,第二个值为 TODO  中国民生银行内控合规CONFIDENCE系统核心功能与操作指引
//        activitys.add(new ActivityModel("21482","16072441"));//第一个值为 课程的ID,第二个值为  中国民生银行法律事务管理介绍
        activitys.add(new ActivityModel("29117","16271054"));//公文培训微课堂——发文人人知
//
//
//
        logger.info("开始时间:"+LocalDateTime.now().toString());

        CountDownLatch totalLatcher=new CountDownLatch(activitys.size());
        long totalStartTime=System.currentTimeMillis();
        for(ActivityModel activityModel:activitys){
            new Thread(()->{
                service.executeStudyCourse(courseCookie,activityModel,totalLatcher);
            }).start();

        }

        //总的阻塞
        try {
            totalLatcher.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long totalEndTime=System.currentTimeMillis();
        logger.info("全部执行完成,总花费时间:"+(totalEndTime-totalStartTime)/1000+"秒");

//         LocalDateTime localDateTime=LocalDateTime.now();
//         long mills=localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
//         localDateTime=localDateTime.plusSeconds(100);
//         long saveMills=localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
//        System.out.println(mills);
//        System.out.println("saveMills="+saveMills);
//        System.out.println(System.currentTimeMillis());

//        String lableId="554162374";
//        String curJsSessionId="MxI5LDW8H8UJxBt63hTdehGchD6BXYYlNEZ9wD6pqcUJGTVptxcc";
////        service.courseList(cookie,lableId,curJsSessionId);
////        //f9d54db2656c494c74ec1e7683113bc676717abc733d3548dfdcfa0b61332c4501fb609d59e807a3
//        String courseId="29268";
//////        String data=service.openCourse(cookie,courseId);
//////        System.out.println("data="+data);
//        String data="f9d54db2656c494c41eb191ced381938ce105423cd2dbc3f06392ce5f6e31b0d745b8ead723ac151";
//////        service.sso(cookie,courseId);
//        String result=service.toCourseDetail(courseCookie,courseId,data);
//        logger.info("result===================="+result);
    }

}
